<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<div class="w-1200 margin-0-auto page-warp clear">
    <div class="page">
        <div class="p-wrap">
                <span class="p-num">
                	<input type="hidden" name="totalPages" id="totalPageProduct" value="${page2.totalPages }" />
                	<input type="hidden" name="pageProduct" id="pageProduct" value="${page2.page }" />
                	<input type="hidden" name="styleID" id="styleID" value="${styleID }" />
                	<input type="hidden" name="brandID" id="brandID" value="${brandID }" />
                	<input type="hidden" name="categoryID" id="categoryID" value="${query.categoryID }" />
                	<input type="hidden" name="sortType" id="sortType" value="${sortType }" />
                	<c:choose>  
					   <c:when test="${page2.page == 1}">
					   	<a class="pn-prev2 disabled" ><i>&lt;</i><em>上一页</em></a>
					   </c:when>  
					   <c:otherwise>
					   	<a class="pn-prev2"><i>&lt;</i><em>上一页</em></a>
					   </c:otherwise>  
					</c:choose>  
					<c:choose>  
						<c:when test="${page2.totalPages < 8}">
							<c:forEach begin="1" end="${page2.totalPages }" varStatus="s">
								<c:choose>  
								   <c:when test="${s.index == page2.page	 }">
								   	<a class="curr page-item2">${s.index }</a>
								   </c:when>  
								   <c:otherwise>
								   	<a class="page-item2">${s.index }</a>
								   </c:otherwise>  
								</c:choose>  
							</c:forEach>
						</c:when>	
						<c:otherwise>
							<c:choose>
								<c:when test="${page2.page < 4 }">
									<c:forEach begin="1" end="3" varStatus="s">
										<c:choose>  
										   <c:when test="${s.index == page2.page	 }">
										   	<a class="curr page-item2">${s.index }</a>
										   </c:when>  
										   <c:otherwise>
										   	<a class="page-item2">${s.index }</a>
										   </c:otherwise>  
										</c:choose>
									</c:forEach>
									<b class="pn-break" class="page-item2"> …</b>
									<a class="page-item2">${page2.totalPages }</a>
								</c:when>
								<c:when test="${page2.page > page2.totalPages-3 }">
									<a class="page-item2">1</a>
									<b class="pn-break" class="page-item2"> …</b>
									<c:forEach begin="${page2.totalPages-3 }" end="${page2.totalPages }" varStatus="s">
										<c:choose>  
										   <c:when test="${s.index == page2.page	 }">
										   	<a class="curr page-item2">${s.index }</a>
										   </c:when>  
										   <c:otherwise>
										   	<a class="page-item2">${s.index }</a>
										   </c:otherwise>  
										</c:choose>
									</c:forEach>
								</c:when>
								<c:otherwise>
									<a class="page-item2">1</a>
									<b class="pn-break" class="page-item2"> …</b>
									<c:forEach begin="${page2.page-1 }" end="${page2.page+1 }" varStatus="s">
										<c:choose>  
										   <c:when test="${s.index == page2.page	 }">
										   	<a class="curr page-item2">${s.index }</a>
										   </c:when>  
										   <c:otherwise>
										   	<a class="page-item2">${s.index }</a>
										   </c:otherwise>  
										</c:choose>
									</c:forEach>
									<b class="pn-break" class="page-item2"> …</b>
									<a class="page-item2">${page2.totalPages }</a>
								</c:otherwise>
							</c:choose>
						</c:otherwise>
					</c:choose>
					
					
					<c:choose>  
					   <c:when test="${page2.page == page2.totalPages}">
					   	<a class="pn-next2 disabled">下一页<i>&gt;</i></a>
					   </c:when>  
					   <c:otherwise>
					   	<a class="pn-next2">下一页<i>&gt;</i></a>
					   </c:otherwise>  
					</c:choose>
					
                    </span>
                <span class="p-skip">
                    <em>共<b>${page2.totalPages }</b>页&nbsp;&nbsp;</em>
                </span>
        </div>
    </div>
  </div>
  <script type="text/javascript">
	var page = $('#pageProduct').val();
	var pageint = parseInt(page);
	var totalPage = $('#totalPageProduct').val();
	var styleID = $('#styleID').val();
	var brandID = $('#brandID').val();
	var categoryID = $('#categoryID').val();
	var sortType = $('#sortType').val();
	
	function prevPage2() {   //前一页
		var prevPage = parseInt($('#pageProduct').val()) - 1;
		gotoPageProduct(prevPage,styleID, brandID, categoryID, sortType);
	}
	
	function nextPage2() {   //后一页
		var nextPage = pageint + 1;
		gotoPageProduct(nextPage,styleID, brandID, categoryID, sortType);
	}
	
	function clickPage2(pageNum) {   //点击页码前进
		gotoPageProduct(pageNum,styleID, brandID, categoryID, sortType);
	}
	
    $(document).ready(function(){
        $('.pn-prev2').on('click',function() {
	    	if(!$(this).hasClass('disabled')) {
	    		prevPage2();
	    	}
	    });
	    $('.pn-next2').on('click',function() {
	    	if(!$(this).hasClass('disabled')) {
	    		nextPage2();
	    	}
	    });
	    $('.page-item2').on('click',function() {
	    	var pageNum = $(this).text();
	    	clickPage2(pageNum);
	    });
    }); 
 </script>